package com.example.demo.controller;

import com.example.demo.service.NameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@CrossOrigin
@RestController
@RequestMapping("/api")
public class NameController {

    @Autowired
    private NameService nameService;
    
    @GetMapping("/saveName")
    public String saveNames() {
        try {
            String filePath = "D:\\Desktop\\姓名.txt";
            nameService.saveNamesFromFile(filePath);
            return "Names saved successfully.";
        } catch (IOException e) {
            e.printStackTrace();
            return "Error occurred while saving names.";
        }
    }

    @GetMapping("/getRandomName")
    public String getRandomName() {
        return nameService.getRandomName();
    }
    
    // 格式化图片名称
    @GetMapping("/formatImageNames")
    public String formatImageNames(){
        return nameService.formatImageNames();
    } 
    
    // 重置所有名称可使用次数
    @PostMapping("/resetAllNames")
    public String resetAllNames(){
        return nameService.resetAllNames();
    }
}    